from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "王牌机战"

    def game_alert(self):
        self.alert_close_by_file('./game/img/王牌机战')

    def handle_main(self):
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/王牌机战/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        if self.not_prize_handle():
            return False

        self.game_alert()

        self.img_click_if_exists('点击闯关', './game/img/王牌机战/game_main.png', './game/img/王牌机战/play1.png')

        w, h = self.d.window_size()
        while not self.check_done():
            self.img_click_if_exists('点击第1关', './game/img/王牌机战/play1.png', './game/img/王牌机战/play1_alert.png')
            self.log_msg("点击出击")
            # self.img_click('./game/img/王牌机战/play1_01.png')
            self.d.click(600, 1570)
            self.d.sleep(2)
            self.log_msg("等待进入战斗主界面")
            self.img_exit('./game/img/王牌机战/play_main.png', 100)
            self.log_msg("已进入战斗主界面")

            while not self.img_exit('./game/img/王牌机战/play_done_01.png', 1):
                self.log_msg("战斗中，左右移动", False)
                for i in range(3):
                    self.d.swipe(w * 0.1, h / 2, w - (w * 0.1), h / 2, 0.2)
                    self.d.swipe(w - (w * 0.1), h / 2, w * 0.1, h / 2, 0.2)
            self.log_msg("战斗结束")
            self.log_msg("点击领取")
            self.img_click('./game/img/王牌机战/play_done_01.png')
            self.img_click('./game/img/王牌机战/play_done_02.png')
            self.d.sleep(2)

            self.game_alert()

        return True
